package com.wangchao.administrator.zenmechi.ui.specialactivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.special.DataBean;

import java.util.List;

/**
 * Created by My on 2016/10/19.
 */
public class ListSpecAdapter extends BaseAdapter {
    private List<DataBean> beanList;
    private Context context;

    public ListSpecAdapter(List<DataBean> beanList, Context context) {
        this.beanList = beanList;
        this.context = context;
    }

    public void setBeanList(List<DataBean> beanList) {
        this.beanList = beanList;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int i) {
        return beanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    MyViewHolder myViewHolder;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null)
        {
            view= LayoutInflater.from(context).inflate(R.layout.item_lv_spec,null);
            myViewHolder=new MyViewHolder();
            myViewHolder.imageView= (ImageView) view.findViewById(R.id.iv_spec);
            myViewHolder.title= (TextView) view.findViewById(R.id.tv_name_spec);
            myViewHolder.marprice= (TextView) view.findViewById(R.id.tv_marpri_spec);
            myViewHolder.truepri= (TextView) view.findViewById(R.id.tv_truepri_spec);
            myViewHolder.truepriunit= (TextView) view.findViewById(R.id.tv_truepriunit_spec);
            view.setTag(myViewHolder);
        }
        else {
            myViewHolder= (MyViewHolder) view.getTag();
        }
        Glide.with(context).load(beanList.get(i).getPic()).into( myViewHolder.imageView);
        myViewHolder.title.setText(beanList.get(i).getName());
        String stringmarket="市场参考价"+beanList.get(i).getOriginal_price()+"元/"+
                beanList.get(i).getMarket_unit()+ beanList.get(i).getMarket_unit();
        myViewHolder.marprice.setText(stringmarket);
        String truepriString=beanList.get(i).getSpecial_price()+"元/";
        myViewHolder.truepri.setText(truepriString);
        String unitString=beanList.get(i).getMarket_unit()+beanList.get(i).getMarket_unit_name();
        myViewHolder.truepriunit.setText(unitString);
        return  view;
    }
    public static class MyViewHolder{
        ImageView imageView;
        TextView title,marprice,truepri,truepriunit;
    }
}
